package com.share.three.springCluster;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

@Service
public class Sender {
	@Autowired
	JmsTemplate jmsTemplate;

	public void sendMessage() {
		for (int i = 0; i < 5000; i++) {
			Msg msg = new Msg(i);
			jmsTemplate.send(msg);
			System.out.println("发送消息： " + msg.toString());
		}
	}

}

class Msg implements MessageCreator {

	int i;

	public int getI() {
		return i;
	}

	public void setI(int i) {
		this.i = i;
	}

	public Msg(int i) {
		super();
		this.i = i;
	}
	
	

	@Override
	public Message createMessage(Session session) throws JMSException {
		return session.createTextMessage("我是 message： " + i);
	}

	@Override
	public String toString() {
		return "Msg [i=" + i + "]";
	}
	
}
